.class public Lcom/vividsolutions/jts/algorithm/CentroidArea;
.super Ljava/lang/Object;
.source "CentroidArea.java"


# instance fields
.field private areasum2:D

.field private basePt:Lcom/vividsolutions/jts/geom/Coordinate;

.field private cg3:Lcom/vividsolutions/jts/geom/Coordinate;

.field private triangleCent3:Lcom/vividsolutions/jts/geom/Coordinate;


# direct methods
.method public constructor <init>()V
    .locals 3

    .line 59
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const/4 v0, 0x0

    .line 53
    iput-object v0, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->basePt:Lcom/vividsolutions/jts/geom/Coordinate;

    .line 54
    new-instance v1, Lcom/vividsolutions/jts/geom/Coordinate;

    invoke-direct {v1}, Lcom/vividsolutions/jts/geom/Coordinate;-><init>()V

    iput-object v1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->triangleCent3:Lcom/vividsolutions/jts/geom/Coordinate;

    const-wide/16 v1, 0x0

    .line 55
    iput-wide v1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->areasum2:D

    .line 56
    new-instance v1, Lcom/vividsolutions/jts/geom/Coordinate;

    invoke-direct {v1}, Lcom/vividsolutions/jts/geom/Coordinate;-><init>()V

    iput-object v1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->cg3:Lcom/vividsolutions/jts/geom/Coordinate;

    .line 60
    iput-object v0, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->basePt:Lcom/vividsolutions/jts/geom/Coordinate;

    return-void
.end method

.method private add(Lcom/vividsolutions/jts/geom/Polygon;)V
    .locals 2

    .line 111
    invoke-virtual {p1}, Lcom/vividsolutions/jts/geom/Polygon;->getExteriorRing()Lcom/vividsolutions/jts/geom/LineString;

    move-result-object v0

    invoke-virtual {v0}, Lcom/vividsolutions/jts/geom/LineString;->getCoordinates()[Lcom/vividsolutions/jts/geom/Coordinate;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->addShell([Lcom/vividsolutions/jts/geom/Coordinate;)V

    const/4 v0, 0x0

    .line 112
    :goto_0
    invoke-virtual {p1}, Lcom/vividsolutions/jts/geom/Polygon;->getNumInteriorRing()I

    move-result v1

    if-ge v0, v1, :cond_0

    .line 113
    invoke-virtual {p1, v0}, Lcom/vividsolutions/jts/geom/Polygon;->getInteriorRingN(I)Lcom/vividsolutions/jts/geom/LineString;

    move-result-object v1

    invoke-virtual {v1}, Lcom/vividsolutions/jts/geom/LineString;->getCoordinates()[Lcom/vividsolutions/jts/geom/Coordinate;

    move-result-object v1

    invoke-direct {p0, v1}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->addHole([Lcom/vividsolutions/jts/geom/Coordinate;)V

    add-int/lit8 v0, v0, 0x1

    goto :goto_0

    :cond_0
    return-void
.end method

.method private addHole([Lcom/vividsolutions/jts/geom/Coordinate;)V
    .locals 5

    .line 127
    invoke-static {p1}, Lcom/vividsolutions/jts/algorithm/CGAlgorithms;->isCCW([Lcom/vividsolutions/jts/geom/Coordinate;)Z

    move-result v0

    const/4 v1, 0x0

    .line 128
    :goto_0
    array-length v2, p1

    add-int/lit8 v2, v2, -0x1

    if-ge v1, v2, :cond_0

    .line 129
    iget-object v2, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->basePt:Lcom/vividsolutions/jts/geom/Coordinate;

    aget-object v3, p1, v1

    add-int/lit8 v1, v1, 0x1

    aget-object v4, p1, v1

    invoke-direct {p0, v2, v3, v4, v0}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->addTriangle(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Z)V

    goto :goto_0

    :cond_0
    return-void
.end method

.method private addShell([Lcom/vividsolutions/jts/geom/Coordinate;)V
    .locals 5

    .line 120
    invoke-static {p1}, Lcom/vividsolutions/jts/algorithm/CGAlgorithms;->isCCW([Lcom/vividsolutions/jts/geom/Coordinate;)Z

    move-result v0

    xor-int/lit8 v0, v0, 0x1

    const/4 v1, 0x0

    .line 121
    :goto_0
    array-length v2, p1

    add-int/lit8 v2, v2, -0x1

    if-ge v1, v2, :cond_0

    .line 122
    iget-object v2, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->basePt:Lcom/vividsolutions/jts/geom/Coordinate;

    aget-object v3, p1, v1

    add-int/lit8 v1, v1, 0x1

    aget-object v4, p1, v1

    invoke-direct {p0, v2, v3, v4, v0}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->addTriangle(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Z)V

    goto :goto_0

    :cond_0
    return-void
.end method

.method private addTriangle(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Z)V
    .locals 6

    if-eqz p4, :cond_0

    const-wide/high16 v0, 0x3ff0000000000000L    # 1.0

    goto :goto_0

    :cond_0
    const-wide/high16 v0, -0x4010000000000000L    # -1.0

    .line 135
    :goto_0
    iget-object p4, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->triangleCent3:Lcom/vividsolutions/jts/geom/Coordinate;

    invoke-static {p1, p2, p3, p4}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->centroid3(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;)V

    .line 136
    invoke-static {p1, p2, p3}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->area2(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;)D

    move-result-wide p1

    .line 137
    iget-object p3, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->cg3:Lcom/vividsolutions/jts/geom/Coordinate;

    iget-wide v2, p3, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    mul-double v0, v0, p1

    iget-object p1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->triangleCent3:Lcom/vividsolutions/jts/geom/Coordinate;

    iget-wide v4, p1, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    mul-double v4, v4, v0

    add-double/2addr v2, v4

    iput-wide v2, p3, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    .line 138
    iget-wide v2, p3, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    iget-wide p1, p1, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    mul-double p1, p1, v0

    add-double/2addr v2, p1

    iput-wide v2, p3, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    .line 139
    iget-wide p1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->areasum2:D

    add-double/2addr p1, v0

    iput-wide p1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->areasum2:D

    return-void
.end method

.method private static area2(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;)D
    .locals 8

    .line 159
    iget-wide v0, p1, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    iget-wide v2, p0, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    sub-double/2addr v0, v2

    iget-wide v4, p2, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    iget-wide v6, p0, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    sub-double/2addr v4, v6

    mul-double v0, v0, v4

    iget-wide v4, p2, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    sub-double/2addr v4, v2

    iget-wide p0, p1, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    sub-double/2addr p0, v6

    mul-double v4, v4, p0

    sub-double/2addr v0, v4

    return-wide v0
.end method

.method private static centroid3(Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;Lcom/vividsolutions/jts/geom/Coordinate;)V
    .locals 4

    .line 148
    iget-wide v0, p0, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    iget-wide v2, p1, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    add-double/2addr v0, v2

    iget-wide v2, p2, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    add-double/2addr v0, v2

    iput-wide v0, p3, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    .line 149
    iget-wide v0, p0, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    iget-wide p0, p1, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    add-double/2addr v0, p0

    iget-wide p0, p2, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    add-double/2addr v0, p0

    iput-wide v0, p3, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    return-void
.end method

.method private setBasePoint(Lcom/vividsolutions/jts/geom/Coordinate;)V
    .locals 1

    .line 106
    iget-object v0, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->basePt:Lcom/vividsolutions/jts/geom/Coordinate;

    if-nez v0, :cond_0

    .line 107
    iput-object p1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->basePt:Lcom/vividsolutions/jts/geom/Coordinate;

    :cond_0
    return-void
.end method


# virtual methods
.method public add(Lcom/vividsolutions/jts/geom/Geometry;)V
    .locals 2

    .line 71
    instance-of v0, p1, Lcom/vividsolutions/jts/geom/Polygon;

    const/4 v1, 0x0

    if-eqz v0, :cond_0

    .line 72
    check-cast p1, Lcom/vividsolutions/jts/geom/Polygon;

    .line 73
    invoke-virtual {p1}, Lcom/vividsolutions/jts/geom/Polygon;->getExteriorRing()Lcom/vividsolutions/jts/geom/LineString;

    move-result-object v0

    invoke-virtual {v0, v1}, Lcom/vividsolutions/jts/geom/LineString;->getCoordinateN(I)Lcom/vividsolutions/jts/geom/Coordinate;

    move-result-object v0

    invoke-direct {p0, v0}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->setBasePoint(Lcom/vividsolutions/jts/geom/Coordinate;)V

    .line 74
    invoke-direct {p0, p1}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->add(Lcom/vividsolutions/jts/geom/Polygon;)V

    goto :goto_1

    .line 76
    :cond_0
    instance-of v0, p1, Lcom/vividsolutions/jts/geom/GeometryCollection;

    if-eqz v0, :cond_1

    .line 77
    check-cast p1, Lcom/vividsolutions/jts/geom/GeometryCollection;

    .line 78
    :goto_0
    invoke-virtual {p1}, Lcom/vividsolutions/jts/geom/GeometryCollection;->getNumGeometries()I

    move-result v0

    if-ge v1, v0, :cond_1

    .line 79
    invoke-virtual {p1, v1}, Lcom/vividsolutions/jts/geom/GeometryCollection;->getGeometryN(I)Lcom/vividsolutions/jts/geom/Geometry;

    move-result-object v0

    invoke-virtual {p0, v0}, Lcom/vividsolutions/jts/algorithm/CentroidArea;->add(Lcom/vividsolutions/jts/geom/Geometry;)V

    add-int/lit8 v1, v1, 0x1

    goto :goto_0

    :cond_1
    :goto_1
    return-void
.end method

.method public getCentroid()Lcom/vividsolutions/jts/geom/Coordinate;
    .locals 8

    .line 98
    new-instance v0, Lcom/vividsolutions/jts/geom/Coordinate;

    invoke-direct {v0}, Lcom/vividsolutions/jts/geom/Coordinate;-><init>()V

    .line 99
    iget-object v1, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->cg3:Lcom/vividsolutions/jts/geom/Coordinate;

    iget-wide v2, v1, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    const-wide/high16 v4, 0x4008000000000000L    # 3.0

    div-double/2addr v2, v4

    iget-wide v6, p0, Lcom/vividsolutions/jts/algorithm/CentroidArea;->areasum2:D

    div-double/2addr v2, v6

    iput-wide v2, v0, Lcom/vividsolutions/jts/geom/Coordinate;->x:D

    .line 100
    iget-wide v1, v1, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    div-double/2addr v1, v4

    div-double/2addr v1, v6

    iput-wide v1, v0, Lcom/vividsolutions/jts/geom/Coordinate;->y:D

    return-object v0
.end method
